<template>
    <div class="container">
        <my-search :fields="fieldsList" :baseNumber="2" @onSearch="searchForm" @onReset="resetForm" />
        <div class="btn">
            <el-button type="info" plain size="mini" @click="go('add')">新增</el-button>
            <el-button type="info" plain size="mini" @click="del()">删除</el-button>

        </div>
        <div class="table-list">

            <my-table v-loading="loading" ref="myEltable" style="width: 100%" 
            row-key="id" :showsummary="false" :columns="tableColumns" 
            :tableData="tableDatas" :pageNum="queryObj.pageNo" 
            :pageSize="queryObj.pageSize" :totalPage="total" 
            :height="$store.state.app.windowHeight - 210"
             max-height="660px" :current="false" @onCurrentChange="changepageNo" :ifSelect="true" @onPageSizeChange="changePageSize" highlight-current-row @onSelectionChange="onSelectionChange" />
        </div>
    </div>
</template>

<script>
import { queryList, deleteScbgxx } from '@/api/zcgj/yzgj'
export default {
    name: 'qyfpmx',

    data() {
        return {
            loading: false,
            fieldsList: [
                {
                    label: '纳税人名称',
                    field: 'qymc',
                    type: 'text',
                    value: ''
                },


                {
                    label: '上传日期',
                    field: 'date',
                    type: 'daterange', // daterange
                    value: [],
                    options: [
                        {
                            field: 'scrqq',
                            value: ''
                        },
                        {
                            field: 'scrqz',
                            value: ''
                        }
                    ],
                    change: value => {
                        // this.changxm(value);
                    }
                }


            ],
            //右侧表格开始
            tableColumns: [
                {
                    label: '纳税人名称',
                    prop: 'qymc',
                    align: 'center',
                    // minWidth: 275,
                    render: (h, params) => {
                        // onClick={() => this.upload(params.row)}
                        return (
                            <div class="underline-text" onClick={() => this.go('edit', params.row)}>
                                {params.row.qymc}
                            </div>
                        );
                    }
                },
                {
                    label: '年度',
                    prop: 'sjnd',
                    align: 'center',

                },
                {
                    label: '数据文件',
                    prop: 'wjsl',
                    align: 'center',

                },
                {
                    label: '说明',
                    prop: 'illustrate',
                    align: 'center',

                },
                {
                    label: '上传日期',
                    prop: 'scsj',
                    align: 'center',

                },
                {
                    label: '上传人',
                    prop: 'scry',
                    align: 'center',

                }



            ],
            tableDatas: []
            , queryObj: {
                qymc: '', //公司名称
                scrqq: '',
                scrqz: '',
                pageNo: 1,
                pageSize: 20
            },
            total: 0,
            selectedRows: []
        }
    },

    mounted() {
         this.getTableData();
    },
    methods: {

        searchForm(params) {
            console.log(params, '查询条件');
            this.queryObj.qymc = params.qymc || '';
            this.queryObj.scrqq = params.scrqq || '';
            this.queryObj.scrqz = params.scrqz || '';
            this.getTableData();
        },
        resetForm() {
            for (let key in this.queryObj) {
                if (key == 'pageNo') {
                    this.queryObj[key] = 1;
                } else if (key == 'pageSize') {
                    this.queryObj[key] = 20;
                } else {
                    this.queryObj[key] = '';
                }
            }
            this.getTableData();
        },
        getTableData() {
            this.loading = true
            console.log(this.queryObj)
            queryList(this.queryObj).then(res => {
                this.loading = false
                this.tableDatas = res.data.records
                this.total = res.data.total
            })
        },
        changepageNo(currPage) {
            this.queryObj.pageNo = currPage;
            this.getTableData();
        },
        changePageSize(pageSize) {
            this.queryObj.pageSize = pageSize;
            this.getTableData();
        },
        onSelectionChange(selectedRows) {
            this.selectedRows = selectedRows;
        },
        del() {
            if (this.selectedRows.length > 0) {
                this.loading = true;
                this.$confirm('该删除后将不可恢复，是否删除？', '友情提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    cancelButtonClass: 'JmconfirmCancelButton',
                    type: 'warning'
                }).then(() => {
                    let ids = []
                    this.selectedRows.forEach(item => {
                        ids.push({
                            qymc: item.qymc, sjnd: item.sjnd
                        })
                    })
                    deleteScbgxx({ syList: ids }).then(result => {
                        this.loading = false;
                        if (result && result.code == 200) {
                            this.$message.success('删除成功');
                            this.getTableData();
                        } else {
                            this.$message.error('删除数据失败！');
                        }
                    })
                        .catch(error => {
                            this.loading = false;
                        })
                })

            } else {
                this.$message.error('请选择一条数据删除');
                return false;
            }
        },
        go(name, params) {
            this.$emit('changePage', name, params);
        },
    }
}
</script>

<style lang="scss" scoped>
.container {
    height: 100%;
    width: 100%;
    background-color: #fff;

    .btn {
        padding: 8px 8px 8px 0;
    }
    .kplist {
        text-align: right;
        span {
            font-size: 14px;
            font-weight: normal;
            color: rgba(0, 0, 0, 0.56);
        }
    }
}
::v-deep .underline-text {
    text-decoration: underline;
    cursor: pointer;
    overflow: hidden;
    color: #409eff;
}
 ::v-deep .el-date-editor {
    width: 220px;
}
</style>
